import request from '@/utils/request'
import type { AxiosResponse } from 'axios'
import { ElMessage } from 'element-plus'

//定义接口
interface fetchOrderEditType {
  id: number
  orderNo: string
  orderTime: string
  phone: string
  consignee: string
  deliverAddress: string
  deliveryTime: string
  remarks: string
  orderAmount: string
  orderState: string
}
interface LoginResponse {
  code: number
  msg: string
}
interface fetchOrderListType {
  currentPage: number
  pageSize: number
  orderNo?: string
  consignee?: string
  phone?: string
  orderState?: string
  data?: string
}
interface fetchOrderSearchType {
  currentPage: number
  pageSize: number
  orderNo?: string
  consignee?: string
  phone?: string
  orderState?: string
  data?: string
}
//二次封装，只需要传入参数，提取url以及处理返回的数据
export const fetchOrderEdit = async (data: fetchOrderEditType) => {
  const res: AxiosResponse<LoginResponse> = await request.post('/order/edit', data)

  if (res.data.code === 0) {
    ElMessage({
      type: 'success',
      message: res.data.msg,
    })
  }
  if (res.data.code === 1) {
    ElMessage({
      type: 'warning',
      message: '修改订单失败',
    })
  }
  return res.data
}
//二次封装，只需传入参数
export const fetchOrderList = async (data: fetchOrderListType) => {
  const res = await request.get('/order/list', data)
  return res.data
}
export const fetchOrderSearch = async (data: fetchOrderSearchType) => {
  const res = await request.get('/order/list', data)
  return res.data
}
